package org.budo.sms.service.leadyea;

import java.util.Map;

import org.budo.support.http.client.Request;
import org.budo.support.http.client.Response;
import org.budo.support.java.net.util.UrlEncodeUtil;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Getter
@Setter
@Slf4j
public class BudoLeadyeaSmsServiceImpl implements BudoLeadyeaSmsService {
    private static final String API_URL = "http://118.178.105.224:8088/sms_utf.jsp";

    private String usr;

    private String pwd;

    @Override
    public String sendSms(String to, String template, Map<String, Object> parameters) {
        String url = API_URL //
                + "?tjpc=" + System.nanoTime() //
                + "&usr=" + this.getUsr() //
                + "&pwd=" + this.getPwd() //
                + "&mobile=" + to //
                + "&msg=" + UrlEncodeUtil.encode(template);

        Request request = new Request();
        request.setUrl(url);

        Response response = request.execute();

        String responseBody = response.getBody();

        log.info("#27 response=" + response + ", request=" + request);
        return responseBody;
    }
}